package com.example.demo.comtroller;

import com.example.demo.Result;
import com.example.demo.bean.Account;
import com.example.demo.bean.ClassGrade;
import com.example.demo.service.AccountService;
import org.springframework.web.util.HtmlUtils;

public class AccountController {
    AccountService accountService;
    public Result login(Account requestAccount){
        String account_num = requestAccount.getAccount_num();
        account_num = HtmlUtils.htmlEscape(account_num);
        Account account = accountService.get(account_num, requestAccount.getPassword());
        if (null == account) {
            return new Result(400);
        } else {
            return new Result(200);
        }
    }
    public Result addAccount(Account requestAccount){
        Boolean result=accountService.addAccount(requestAccount);
        if (result==true) {
            return new Result(400);
        } else {
            return new Result(200);
        }
    }
    public Result deleteAccount(Account requestAccount){
        Boolean result=accountService.deleteAccount(requestAccount);
        if (result==true) {
            return new Result(400);
        } else {
            return new Result(200);
        }
    }
    public Result updateAccount(Account accountToUpdate,Account newAccount){
        Boolean result=accountService.updateAccount(accountToUpdate,newAccount);
        if (result==true) {
            return new Result(400);
        } else {
            return new Result(200);
        }
    }
    public Result setHeadTeacher(Account account, ClassGrade classGrade){
        Boolean result=accountService.setHeadTeacher(account,classGrade);
        if(result==true){
            return new Result(400);
        }
        return new Result(200);
    }
}
